/********************************************************************
	created:	2009:12:14   23:55:04
	filename: 	progresstrack.cpp
	author:		zouyf
	describe:	
*********************************************************************/
#include "stdafx.h"
#include "progresstrack.h"
#include "ui_widget_utils.h"

void FProgressTrack::OnLButtonDown(UINT nFlags, CPoint point)
{
	::SendMessage(::GetParent(m_hWnd), WM_USER_STARTSETPROGRESS, NULL, NULL);
	SetMsgHandled(FALSE);
}

void FProgressTrack::OnLButtonUp(UINT nFlags, CPoint point)
{
	::SendMessage(::GetParent(m_hWnd), WM_USER_ENDSETPROGRES, NULL, NULL);
	SetMsgHandled(FALSE);
}

DWORD FProgressTrack::OnPrePaint(int , LPNMCUSTOMDRAW )
{
	return CDRF_NOTIFYITEMDRAW;
}

DWORD FProgressTrack::OnItemPrePaint(int nId, LPNMCUSTOMDRAW pNm)
{
	if (pNm->dwItemSpec == TBCD_CHANNEL)
	{
		CDCHandle dc(pNm->hdc);
		CBrush brush;
		brush.CreateSolidBrush(RGB(125, 125, 125));
		dc.FillRect(&(pNm->rc), brush.m_hBrush);

		int nPos = this->GetPos();
		brush.DeleteObject();
		brush.CreateSolidBrush(RGB(255, 125, 125));
		RECT preRect;
		preRect.left = pNm->rc.left;
		preRect.right = pNm->rc.right * (nPos / 100.0);
		preRect.top = pNm->rc.top;
		preRect.bottom = pNm->rc.bottom;
		dc.FillRect(&preRect, brush.m_hBrush);

		return CDRF_SKIPDEFAULT;
	}
	else if (pNm->dwItemSpec == TBCD_THUMB)
	{
		CDCHandle dc(pNm->hdc);
		CBrush brush;
		brush.CreateSolidBrush(RGB(0, 125, 125));
		dc.FillRect(&(pNm->rc), brush.m_hBrush);
		return CDRF_SKIPDEFAULT;
	}
	else if (pNm->dwItemSpec == TBCD_TICS)
	{
		CDCHandle dc(pNm->hdc);
		CBrush brush;
		brush.CreateSolidBrush(RGB(0, 125, 125));
		dc.FillRect(&(pNm->rc), brush.m_hBrush);
		return CDRF_SKIPDEFAULT;
	}
	return CDRF_SKIPDEFAULT;
}
